class Solution{
public:
	vector<int>sortedSquares(vector<int>&nums){
		int k=nums.size()-1;
		vector<int>ans(k+1);
		int i=0,j=k;
		while(i<=j){
			int a=nums[i]*nums[i];
			int b=nums[j]*nums[j];
			if(a<b){
				ans[k--]=b;
				j--;
			}
			else {
				ans[k--]=a;
				i++;
			}
		}
		return ans;
	}
};
